//
//  KnowledgePointVC.m
//  SYPerfectDemo
//
//  Created by Lssyyy on 2018/8/13.
//  Copyright © 2018年 Lssyyy. All rights reserved.
//

#import "KnowledgePointVC.h"
#import "ClassifyCell.h"
#import "KnowledgePointDetailVC.h"
@interface KnowledgePointVC ()
@property (nonatomic,strong) NSMutableArray *vcNameArray;
@property (nonatomic,strong) NSArray *contentArray;
@end

@implementation KnowledgePointVC

- (void)viewDidLoad {
    [super viewDidLoad];
}
- (void)addUI{
    [super addUI];
}

- (void)layoutUI{
    [super layoutUI];
}

- (void)config{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"KnowledgePointPList" ofType:@"plist"];
    self.contentArray = [NSArray arrayWithContentsOfFile:path];
    self.title = @"知识点";
    self.view.backgroundColor = RandomColor;
    [self.tableView registerClass:[ClassifyCell class] forCellReuseIdentifier:@"ClassifyCell"];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (NSInteger i = 0; i < self.contentArray.count; i++) {
        dic = [NSMutableDictionary dictionaryWithDictionary:_contentArray[i]];
        [self.vcNameArray addObject:dic];
    }
//    for (NSString *key in [dic allKeys]) {
//        [self.vcNameArray addObject:key];
//    }
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _vcNameArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ClassifyCell *cell = [ClassifyCell dequeueCellWithTableView:tableView indexPath:indexPath];
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:_vcNameArray[indexPath.row]];
    for (NSString *str in [dic allKeys]) {
        [cell configContent:str];
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:_vcNameArray[indexPath.row]];
    for (NSString *key in [dic allKeys]) {
        KnowledgePointDetailVC *vc = [[KnowledgePointDetailVC alloc]init];
        vc.content = [dic objectForKey:key];
        vc.title = key;
        [self.navigationController pushViewController:vc animated:YES];
    }
   NSLog(@"我开发了许多功能在这里");
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (NSMutableArray *)vcNameArray{
    if (!_vcNameArray) {
        _vcNameArray = [NSMutableArray array];
    }
    return _vcNameArray;
}
@end
